package com.szcf.testserial.utils;


public class Constants {	
	//Serial Port
	public static final String SERIAL_DEVICE_NAME 			= "/dev/ttyS3";
	public static final int SERIAL_BAUDRATE					= 9600;
	public static final int SERIAL_INVALID					= 0;
	
	public static final int CHANNEL_TYPE_DISABLE			= 0;		// 禁止使用
	public static final int CHANNEL_TYPE_SPRINGS			= 1;		// 弹簧机、
	public static final int CHANNEL_TYPE_LATTICES			= 2;		// 格子锁、
	public static final int CHANNEL_TYPE_PEDRAIL_POWER		= 3;		// 履带机-开关、
	public static final int CHANNEL_TYPE_PEDRAIL_GRATING	= 4;		// 履带机-光栅
	
	public static final int SERVICE_SERIAL_OPENED 					= 7;		// 串口打开完成
	public static final int SERVICE_SERIAL_UNOPEN 					= 8;		// 串口打开失败
	public static final int SERVICE_SERIAL_RECEIVED 				= 9;		// 串口接收到数据
	

	public static final String COMMAND_ALARM_FLAG					= "FD";		// 命令：红外线报警
	public static final String COMMAND_ALARM_INFRARED_FLAG			= "03";		// 命令：红外线报警
	public static final String COMMAND_ALARM_HIT_FLAG				= "02";		// 命令：撞击报警
	public static final String COMMAND_LATTICES						= "A2";		// 命令：格子锁
	public static final String COMMAND_GOODS_OUT					= "A3";		// 命令：出货
	public static final String COMMAND_PEDRAIL_POWER				= "A4";		// 命令：履带机-开关
	public static final String COMMAND_ERROR_SYSTEM					= "FA";		// 命令：报错－驱动板系统
	public static final String COMMAND_ERROR_OPERATION				= "FB";		// 命令：报错－操作方面
	public static final String COMMAND_DOOR							= "D1";		// 命令：开关门命令
	public static final String COMMAND_ELEVATOR						= "D5";		// 命令：升降机命令
	public static final String COMMAND_READ_LIGHT					= "D7";		// 命令：读光栅状态
	public static final String COMMAND_SENDOUT						= "D8";		// 命令：输送带
	public static final String COMMAND_WARRING_POWER				= "F0";		// 命令：报警开关
	// 命令开始
	public static final String COMMAND_START						= "C1";		// 命令
	public static final String COMMAND_STEP_LIGHT					= "C2";		// 命令
	
	public static final String COMMAND_STATUS_SUCESSFUL				= "A0";
	public static final String COMMAND_STATUS_FAILD					= "0F";
	public static final String COMMAND_DOOR_STATUS_OPEN				= "0B";
	public static final String COMMAND_DOOR_STATUS_CLOSE			= "0A";
	
	//Preference
	public static final String CHANNEL_ROW 							= "CHANNEL_ROW";		// 行高
	public static final String CHANNEL_ROW_OUT_X					= "CHANNEL_ROW_OUT_X";	// 出货X
	public static final String CHANNEL_ROW_OUT_Y				 	= "CHANNEL_ROW_OUT_Y";	// 出货Y
	public static final String MACHINE_OCCLUSION					= "MACHINE_OCCLUSION";	// 输送带命令-遮挡
	public static final String MACHINE_SENDOUT					 	= "MACHINE_SENDOUT";	// 输送带命令-送出
	public static final String COMMAND_ADDRESS_HEIGHT 				= "00";		// 地址码－升降机
	public static final String COMMAND_ADDRESS_MACHINE 				= "01";		// 地址码－货道
	
	// 报警开关 FF0900F00A00FE
	public static String sendCommandWarringPower(boolean power) {
		if (power == true) {
			return CRC16.hexVerification("FF09"+COMMAND_ADDRESS_MACHINE+"F00A00")+"FE";
		} else {
			return CRC16.hexVerification("FF09"+COMMAND_ADDRESS_MACHINE+"F00F00")+"FE";
		}
	}
	
	// 出货命令 FF0C00A30B01010103E3AEFE
	public static String sendCommandGoods(String channelY, String channelX, String turn) {
		return CRC16.hexVerification("FF0C"+COMMAND_ADDRESS_MACHINE+"A30B"+channelY+channelX+turn+"00")+"FE";
	}
	
	// 格子锁出货命令 FF0C00A30B01010103E3AEFE
	public static String sendCommandLattices(String channelY, String channelX) {
		return CRC16.hexVerification("FF0A"+COMMAND_ADDRESS_MACHINE+"A20B"+channelY+channelX)+"FE";
	}
	
	// 履带机-开关出货命令 FF0C00A30B01010103E3AEFE
	public static String sendCommandPedrailPower(String channelY, String channelX, String value) {
		return CRC16.hexVerification("FF0C"+COMMAND_ADDRESS_MACHINE+"A40B"+channelY+channelX+value+"03")+"FE";
	}
	
	// 升降机命令 ff 0c 00 d5 0a 00 12 00 00 64 90 fe
	public static String sendCommandHeight(String height) {
		return CRC16.hexVerification("FF0C"+COMMAND_ADDRESS_HEIGHT+"D50A00"+height+"0000")+"FE";
	}
	
	// 升降机命令 ff 0c 00 d5 0a 00 12 00 00 64 90 fe
	public static String sendCommandHeight2(String y, String x) {
		return CRC16.hexVerification("FF0D"+COMMAND_ADDRESS_HEIGHT+"D500"+y+"00"+x+"0000")+"FE";
	}
	
	// 升降机命令 ff 0c 00 d5 0a 00 12 00 00 64 90 fe
	public static String sendCommandHeight2Reset() {
		return "FF0D"+COMMAND_ADDRESS_HEIGHT+"D500000000000099A9FE";
	}
	
	// 输送带命令 ff 0c 00 d5 0a 00 12 00 00 64 90 fe
	public static String sendCommandSendout(String occlusion, String sendOut) {
		return CRC16.hexVerification("FF0B"+COMMAND_ADDRESS_HEIGHT+"D80A"+occlusion+sendOut+"00")+"FE";
	}
	
	// 输送带命令 ff 0c 00 d5 0a 00 12 00 00 64 90 fe
	public static String sendCommandSendout2(String occlusion, String sendOut) {
		return CRC16.hexVerification("FF0A"+COMMAND_ADDRESS_HEIGHT+"D80A"+occlusion+sendOut)+"FE";
	}
	
	// 自动开门命令 FF0B00D10B000B004CC9FE
	public static String sendCommandDoorOpen() {
		return CRC16.hexVerification("FF09"+COMMAND_ADDRESS_HEIGHT+"D1"+COMMAND_DOOR_STATUS_OPEN+"00")+"FE";
	}
	
	// 自动关门命令 FF0B00D10B000B004CC9FE
	public static String sendCommandDoorClose() {
		return CRC16.hexVerification("FF09"+COMMAND_ADDRESS_HEIGHT+"D1"+COMMAND_DOOR_STATUS_CLOSE+"00")+"FE";
	}
	
	// 读光栅状态命令 
	public static String sendCommandReadLightOne() {
		return CRC16.hexVerification("FF08"+COMMAND_ADDRESS_HEIGHT+"D7A0")+"FE";
	}
	
	// 读光栅状态命令 
	public static String sendCommandReadLightTwo() {
		return CRC16.hexVerification("FF08"+COMMAND_ADDRESS_HEIGHT+"D7A1")+"FE";
	}
	
	// 虚拟命令开始
	public static String visuCommandStart() {
		return CRC16.hexVerification("FF08"+COMMAND_ADDRESS_HEIGHT+COMMAND_START+"A1")+"FE";
	}
	
	// 虚拟命令光
	public static String visuCommandStepLight() {
		return CRC16.hexVerification("FF08"+COMMAND_ADDRESS_HEIGHT+COMMAND_STEP_LIGHT+"A1")+"FE";
	}
	

}
